package ar.edu.itba.pod.legajo48062;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;

import ar.edu.itba.node.NodeInformation;

public class Menu {
	public static ConnectionOptions connectionMenu() throws NumberFormatException, IOException{
		BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));
		
		System.out.println("Desea \n1.Crear un cluster \n2.Conectarse a un cluster");
		int option = Integer.valueOf(lectura.readLine());
		return ConnectionOptions.values()[option-1];
	}
	
	public static OperationOptions operationMenu() throws NumberFormatException, IOException{
		BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));
		
		System.out.println("Opciones \n1. Estadisticas\n2. Desconectar del cluster\n3. Comenzar Simulacion\n4. Agregar PRODUCER\n5. Agregar CONSUMER\n6. Agregar MARKET\n7. Salir");
		int option =Integer.valueOf(lectura.readLine());
		return OperationOptions.values()[option-1];		
	}
	
	public static NodeInformation askLocalInformation() {
		BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));
		int port=0;
		String address=null;
		
		try{
			System.out.println("Ingrese puerto a utilizar:");
			port = Integer.valueOf(lectura.readLine());
			address=InetAddress.getLocalHost().getHostAddress();
		
		}catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}
		return new NodeInformation(address, port, address+":"+port);

	}

	public static NodeInformation askRemoteInformation() throws IOException{
		BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));

		System.out.println("Ingrese Host:");
		String host = lectura.readLine();
		System.out.println("Ingrese Puerto:");
		int port = Integer.valueOf(lectura.readLine());
		
		return new NodeInformation(host, port, "");
	}
	
	public static enum ConnectionOptions{
		CREATE, CONNECT;
	}
	
	public static enum OperationOptions{
		STATISTIC, DISCONNECT, START, ADDPRODUCER, ADDCONSUMER, ADDMARKET, EXIT; 
	}
}
